package com.example.demo.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description
 * @Author liumin0901@sunwayworld.com
 * @Date 2021/5/9 16:46
 */
@Component
public class AvgLatencyProducerInterceptor implements ProducerInterceptor<String,String> {

//    private RedisProperties.Jedis jedis;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Override
    public ProducerRecord onSend(ProducerRecord record) {
        Long totalSentMessage = redisTemplate.opsForValue().increment("totalSentMessage");
        System.out.println("totalSentMessage ="+ totalSentMessage);
//        jedis.incr("totalSentMessage"); return record;
        return record;
    }

    @Override
    public void onAcknowledgement(RecordMetadata recordMetadata, Exception e) {

    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
